package cn.dakaqi.entities;

import cn.dakaqi.entities.user.Volunteer;
import cn.dakaqi.utils.DKQConstant;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by chunyang on 2016/4/17.
 * 志愿者公益记录
 */
@EqualsAndHashCode(callSuper = false)
@SuppressWarnings("unused")

@Entity
@Table(name = "U_ACTIVITY_SIGN")
@Data
@ToString
public class ActivitySign extends IdEntity
{
    private static final long serialVersionUID = -3613355126623861915L;

    private Volunteer volunteer;
    private Activity activity;
    private Date createTime;
    private int times;
    private int delStatus;
    private int status;
    private double lng;
    private double lat;
    private int hasCommnet;//是否已被评论
    private int commnetType = DKQConstant.COMMENT_TYPE;//好中差
    private String platform;        //当前公益时间是属于哪些平台的
    private long recordId;//数据提交至北航时返回的在北航库中的公益记录ID
    private long groupId;   //当前活动记录是哪个社团
    private String orgs;// 当前记录是哪个组织

    @JsonIgnore
    @ManyToOne
    @JoinColumn(name = "VOLUNTEER_ID")
    public Volunteer getVolunteer()
    {
        return volunteer;
    }

    @JsonIgnore
    @ManyToOne
    @JoinColumn(name = "ACTIVITY_ID")
    public Activity getActivity()
    {
        return activity;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+08:00")
    public Date getCreateTime()
    {
        return createTime;
    }

    public long getGroupId()
    {
        return groupId;
    }

    public void setGroupId(long groupId)
    {
        this.groupId = groupId;
    }

    public static ActivitySign build(ActivitySignRecord activitySignRecord,int times,String orgs){
        ActivitySign activitySign = new ActivitySign();

        activitySign.setLat(activitySignRecord.getLat());
        activitySign.setLng(activitySignRecord.getLng());
        activitySign.setVolunteer(activitySignRecord.getVolunteer());
        activitySign.setActivity(activitySignRecord.getActivity());
        activitySign.setTimes(times);
        activitySign.setCreateTime(activitySignRecord.getCreateTime());
        activitySign.setPlatform(activitySignRecord.getActivity().getPlatform());
        activitySign.setGroupId(activitySignRecord.getActivity().getGroup().getId());
        activitySign.setOrgs(orgs);

        return activitySign;
    }
}
